import {myRequest} from "../../api/myRequest";
import $actions from '../constant/actions'
const _TemplateInstanceManage = 'StatTemplateInstanceManage';
const StatTemplateInstance ={
	//******************************实例编辑方法开始*************************************************************************//
	/**
	 * 添加信息
	 * @param record
	 * @returns {Promise<*>}
	 */
	add(record) {
		return myRequest(_TemplateInstanceManage,[{action: $actions.INSTANCE_ADD, data: [record]}]);
	},
	/**
	 * 更新信息
	 * @param record
	 * @returns {Promise<*>}
	 */
	update(record) {
		return myRequest(_TemplateInstanceManage,[{action: $actions.INSTANCE_UPDATE, data: [record]}]);
	},

	/**
	 * 删除信息
	 * @param id
	 * @returns {Promise<*>}
	 */
	delete(filter) {
		return myRequest(_TemplateInstanceManage,[{action: $actions.INSTANCE_DELETE, ...filter}]);
	},
	/**
	 * 按Id删除信息
	 * @param ids
	 * @returns {Promise<*>}
	 */
	deleteById(id) {
		return myRequest(_TemplateInstanceManage,[{action: $actions.INSTANCE_DELETE_BY_ID, id: id}]);
	},

	/**
	 * 批量删除信息
	 * @param ids
	 * @returns {Promise<*>}
	 */
	deleteByIds(ids) {
		return myRequest(_TemplateInstanceManage,[{action: $actions.INSTANCE_DELETE_BY_IDS, ids: ids}]);
	},

	/**
	 * 查询列表
	 * @param filter
	 * @returns {Promise<*>}
	 */
	query(filter) {
		let recipient = [{action: $actions.INSTANCE_QUERY,...filter}]
		return myRequest(_TemplateInstanceManage,recipient);
	},
	/**
	 * 查询列表
	 * @param filter
	 * @returns {Promise<*>}
	 */
	queryIncludeUnpublished(filter) {
		let recipient = [{action: $actions.INSTANCE_QUERY_INCLUDE_UNPUBLISHED,...filter}]
		return myRequest(_TemplateInstanceManage,recipient);
	},
	/**
	 * 分页查询
	 * @param pageNumber
	 * @param pageSize
	 * @param filter
	 * @returns {Promise<unknown | void>}
	 */
	queryByPage(pageNumber, pageSize, filter) {
		let recipient = [{action: $actions.INSTANCE_QUERY_BY_PAGE, pageNumber: pageNumber, pageSize: pageSize,...filter}]
		return myRequest(_TemplateInstanceManage,recipient);
	},
	/**
	 * 运行时注册
	 * @param pointer 注册指针
	 * @param hier  转换成map,如:{"basic":[]}
	 * @returns {*}
	 */
	runRegister(pointer,hier) {
		let recipient = [{action: $actions.INSTANCE_RUN_REGISTER,pointer:pointer,hier:[hier]}]
		return myRequest(_TemplateInstanceManage,recipient);
	},

	/**
	 * 运行时注册
	 * @param pointer 注册指针
	 * @param names  字符数组，如 [a,b]
	 * @returns {*}
	 */
	runUnregister(pointer,names) {
		let recipient = [{action: $actions.INSTANCE_RUN_UNREGISTER,pointer:pointer,names:names}]
		return myRequest(_TemplateInstanceManage,recipient);
	},


	/**
	 * 运行时订阅
	 * @param pointer 订阅指针
	 * @param others 是map,如 {"basic":[]}
	 * @returns {*}
	 */
	runSubscribe(pointer,others) {
		let recipient = [{action: $actions.INSTANCE_RUN_SUBSCRIBE,pointer:pointer,others:others}]
		return myRequest(_TemplateInstanceManage,recipient);
	},

	/**
	 * 运行时取消订阅
	 * @param pointer 取消订阅指针
	 * @param names 字符数组，如 [a,b]
	 * @returns {*}
	 */
	runUnsubscribe(pointer,names) {
		let recipient = [{action: $actions.INSTANCE_RUN_UNSUBSCRIBE,pointer:pointer,names:names}]
		return myRequest(_TemplateInstanceManage,recipient);
	},
	/**
	 * 运行时整体注册，
	 * 1、先将所有已注册的订阅移除，
	 * 2、再将所有已注册的移除
	 * 3、将新要注册的整体订阅
	 * 4、将新要注册的整体注册
	 * @param pointer 注册指针
	 * @param hier  转换成map,如:{"basic":[]}
	 * @returns {*}
	 */
	runAllAddRegister(pointer,hier){
		let recipient = [{action: $actions.INSTANCE_RUN_ALL_ADD_REGISTER,pointer:pointer,hier:[hier]}]
		return myRequest(_TemplateInstanceManage,recipient);
	},
	/**
	 * 运行时束体订阅，
	 * 1、先将所有已订阅的注册移除，
	 * 2、再将所有已订阅的移除
	 * 3、将新要订阅的整体注册
	 * 4、将新要订阅的整体订阅
	 * @param pointer 订阅指针
	 * @param others 是map,如 {"basic":[]}
	 * @returns {*}
	 */
	runAllAddSubscribe(pointer,others) {
		let recipient = [{action: $actions.INSTANCE_RUN_ALL_ADD_SUBSCRIBE,pointer:pointer,others:others}]
		return myRequest(_TemplateInstanceManage,recipient);
	},
	/**
	 * 运行时容器添加注册
	 * @param pointer 注册指针
	 * @param hier  转换成map,如:{"basic":[]}
	 * @returns {*}
	 */
	runAddRegister(pointer,hier){
		let recipient = [{action: $actions.INSTANCE_RUN_ADD_REGISTER,pointer:pointer,hier:[hier]}]
		return myRequest(_TemplateInstanceManage,recipient);
	},
	/**
	 * 运运时容器移除注册
	 * @param pointer 取消订阅指针
	 * @param names 字符数组，如 [a,b]
	 * @returns {*}
	 */
	runRemoveRegister(pointer,names){
		let recipient = [{action: $actions.INSTANCE_RUN_REMOVE_REGISTER,pointer:pointer,names:names}]
		return myRequest(_TemplateInstanceManage,recipient);
	},
	/**
	 * 运行时容器添加订阅
	 * @param pointer 订阅指针
	 * @param others 是map,如 {"basic":[]}
	 * @returns {*}
	 */
	runAddSubscribe(pointer,others) {
		let recipient = [{action: $actions.INSTANCE_RUN_ADD_SUBSCRIBE,pointer:pointer,others:others}]
		return myRequest(_TemplateInstanceManage,recipient);
	},
	/**
	 * 运行时容器移除订阅
	 * @param pointer 取消订阅指针
	 * @param names 字符数组，如 [a,b]
	 * @returns {*}
	 */
	runRemoveSubscribe(pointer,names){
		let recipient = [{action: $actions.INSTANCE_RUN_REMOVE_SUBSCRIBE,pointer:pointer,names:names}]
		return myRequest(_TemplateInstanceManage,recipient);
	},
	//******************************实例摘要方法开始*************************************************************************//
	/**
	 * 简单查询不包括实例属性或大字段信息
	 * @param filter
	 * @returns {Promise<*>}
	 */
	queryInfo(filter) {
		let recipient = [{action: $actions.INSTANCE_QUERY_INFO,...filter}]
		return myRequest(_TemplateInstanceManage,recipient);
	},

	/**
	 * 简单查询不包括实例属性或大字段信息
	 * @param filter
	 * @returns {Promise<*>}
	 */
	queryInfoIncludeUnpublished(filter) {
		let recipient = [{action: $actions.INSTANCE_QUERY_INFO_INCLUDE_UNPUBLISHED,...filter}]
		return myRequest(_TemplateInstanceManage,recipient);
	},

	/**
	 * 查询列表
	 * @param recipient
	 * @returns {Promise<*>}
	 */
	queryInfoByPage(pageNumber, pageSize, filter) {
		let recipient = [{action: $actions.INSTANCE_QUERY_INFO_BY_PAGE, pageNumber: pageNumber, pageSize: pageSize,...filter}]
		return myRequest(_TemplateInstanceManage,recipient);
	},
	//******************************实例订阅方法开始*************************************************************************//
}

export default StatTemplateInstance;
